define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        select: function () {
            $(document).on("click", ".btn-select-two", function () {
                    var ids = Table.api.selectedids(table);
                console.log(ids);
                         Fast.api.close(ids);
            });
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cost/select',//页面路径
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                showToggle: false,
                showExport: false,
                maintainSelected: true,
                searchFormVisible: false, //是否始终显示搜索表单
                // commonSearch: false,//快速搜索
                visible: false,//浏览模式(卡片切换)、显示隐藏列、导出、通用搜索全部隐藏
                showColumns: false,//列，可隐藏不显示的字段
                search:false,//快速搜索，搜索框
                columns: [
                    [
                        {checkbox: true},//隐藏复选框
                        {field: 'product_id', title: __('产品ID')},
                        {field: 'factory_id', title: __('工厂ID'), operate: 'LIKE'},
                        {field: 'factory.title', title: __('工厂名称'), operate: 'LIKE'},
                        {field: 'productname.name', title: __('产品名称'), operate: 'LIKE'},
                        {field: 'cost_name', title: __('费用名称'), operate: 'LIKE'},
                        {field: 'cost_money', title: __('费用项'), operate: 'LIKE'},
                        {field: 'real_money', title: __('工厂收取费用'), operate: 'LIKE'},

                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cost/index' + location.search,
                    add_url: 'cost/add',
                    edit_url: 'cost/edit',
                    del_url: 'cost/del',
                    multi_url: 'cost/multi',
                    import_url: 'cost/import',
                    table: 'cost',
                }
            });

            var table = $("#table");
            // 初始化表格参数配置

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'factory.title', title: __('工厂'), operate: 'LIKE'},
                        {field: 'type', title: __('计费方式'), searchList: {"1":__('固定计费'),"2":__('自定义')}, formatter: Table.api.formatter.status},
                        {field: 'cost_money', title: __('工厂收取费用'), operate:'BETWEEN'},
                        {field: 'real_money', title: __('心喜阅费用'), operate:'BETWEEN'},
                        {field: 'cost_name', title: __('Cost_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'productname.name', title: __('产品名称')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $(document).on("change","#c-factory_id",function (){
                $("#c-product_id").selectPageClear();
            }),
            $("#c-product_id").data("params", function (obj) {

                return {factory_id: $("#c-factory_id").val()};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $(document).on("change","#c-factory_id",function (){
                $("#c-product_id").selectPageClear();
            }),
            $("#c-product_id").data("params", function (obj) {
                return {factory_id: $("#c-factory_id").val()};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
